import axios from 'axios';
import React, { useState, useEffect } from 'react';
export const ResouceLoader = ({ resouceUrl, resouceName, children, }) => {
    const [state, setState] = useState(null);
    useEffect(() => {
        (async () => {
            const response = await axios.get(resouceUrl);
            setState(response.data);
        })()
    }, [resouceUrl])

    return (
        <>
            {
                React.Children.map(children, child => {
                    if (React.isValidElement(child)) {
                        return React.cloneElement(child, { [resouceName]: state });
                    }
                    return child;
                })
            }
        </>
    );
}

